"""
@author:liazylee
@license: Apache Licence
@time: 2022/2/23 15:25
@contact: li233111@gmail.com
# code is far away from bugs with the god animal protecting
    I love animals. They taste delicious.
              ┏┓      ┏┓
            ┏┛┻━━━┛┻┓
            ┃      ☃      ┃
            ┃  ┳┛  ┗┳  ┃
            ┃      ┻      ┃
            ┗━┓      ┏━┛
                ┃      ┗━━━┓
                ┃  神兽保佑    ┣┓
                ┃　永无BUG！   ┏┛
                ┗┓┓┏━┳┓┏┛
                  ┃┫┫  ┃┫┫
                  ┗┻┛  ┗┻┛
"""

# 回调记录
from django.db import models


class CallBackRecord(models.Model):
    """"
    eg:
    "subject": "测试订单",
    "gmt_payment": "2016-11-16 11:42:19",
    "charset": "utf-8",
    "seller_id": "xxxx",
    "trade_status": "TRADE_SUCCESS",
    "buyer_id": "xxxx",
    "auth_app_id": "xxxx",
    "buyer_pay_amount": "0.01",
    "version": "1.0",
    "gmt_create": "2016-11-16 11:42:18",
    "trade_no": "xxxx",
    "fund_bill_list": "[{\"amount\":\"0.01\",\"fundChannel\":\"ALIPAYACCOUNT\"}]",
    "app_id": "xxxx",
    "notify_time": "2016-11-16 11:42:19",
    "point_amount": "0.00",
    "total_amount": "0.01",
    "notify_type": "trade_status_sync",
    "out_trade_no": "xxxx",
    "buyer_logon_id": "xxxx",
    "notify_id": "xxxx",
    "seller_email": "xxxx",
    "receipt_amount": "0.01",
    "invoice_amount": "0.01",
    "sign": "xxx"
    """
    subject = models.CharField(max_length=128, blank=True, null=True, verbose_name='订单名称')
    gmt_payment = models.DateTimeField(blank=True, null=True, verbose_name='支付时间')
    charset = models.CharField(max_length=128, blank=True, null=True, verbose_name='字符集')
    seller_id = models.CharField(max_length=128, blank=True, null=True, verbose_name='卖家支付宝用户号')
    trade_status = models.CharField(max_length=128, blank=True, null=True, verbose_name='交易状态')
    buyer_id = models.CharField(verbose_name='购买id', blank=True, null=True, max_length=128)
    auth_app_id = models.CharField(max_length=128, blank=True, null=True, verbose_name='授权appid')
    buyer_pay_amount = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True, verbose_name='付款金额')
    version = models.CharField(max_length=128, blank=True, null=True, verbose_name='版本')
    gmt_create = models.DateTimeField(blank=True, null=True, verbose_name='交易创建时间')
    trade_no = models.CharField(max_length=128, blank=True, null=True, verbose_name='支付宝交易号')
    fund_bill_list = models.CharField(max_length=128, blank=True, null=True, verbose_name='支付金额信息')
    app_id = models.CharField(max_length=128, blank=True, null=True, verbose_name='appid')
    notify_time = models.DateTimeField(blank=True, null=True, verbose_name='通知时间')
    point_amount = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True, verbose_name='积分支付金额')
    total_amount = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True, verbose_name='订单金额')
    notify_type = models.CharField(max_length=128, blank=True, null=True, verbose_name='通知类型')
    out_trade_no = models.IntegerField(blank=True, null=True, verbose_name='商户订单号')
    buyer_logon_id = models.CharField(max_length=128, blank=True, null=True, verbose_name='买家支付宝账号')
    notify_id = models.CharField(max_length=128, blank=True, null=True, verbose_name='通知校验ID')
    seller_email = models.CharField(max_length=128, blank=True, null=True, verbose_name='卖家支付宝账号')
    receipt_amount = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True, verbose_name='实收金额')
    invoice_amount = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True, verbose_name='发票金额')

    # sign=models.CharField(verbose_name='签名',)
    class Meta:
        verbose_name = '支付宝回调消息'
        verbose_name_plural = verbose_name
        db_table = 't_callback_record'

    def __str__(self):
        return f'{self.subject}-{self.out_trade_no}'
